package com.topka.buynewcar.android.pages;

import io.appium.java_client.android.AndroidDriver;

import java.util.List;

import org.openqa.selenium.WebElement;

import com.topka.buynewcar.base.BasePage;
import com.topka.buynewcar.utils.DeviceInfo;

public class ChooseCityPage extends BasePage {

	private WebElement currentCity;
	
	public ChooseCityPage(AndroidDriver wd) {
		super(wd);
	}
	
	public void clickCurrentCity(){
		currentCity = findViewById("currentCity");
		currentCity.click();
	}
	
	public void clickProvince(String province){
		try{
			List<WebElement> list = findViewsById("cityTv");
			if(list.size()>0){
				return;
			}
		}catch(Exception e){
			
		}
		int width = DeviceInfo.getWidth(wd);
		int height = DeviceInfo.getHeight(wd);
        while(true){
			List<WebElement> list = findViewsById("provinceTv");
			for (WebElement e : list) {
				boolean flag = e.getText().equals(province);
				if(flag){
					e.click();
					return;
				}
				if(e.getText().equals("新疆"))
					return;
			}
			wd.swipe(width/2,height*3/4, width/2,height/4, 1000);
        }
	}
	public void clickCity(){
		List<WebElement> list = findViewsById("cityTv");
		for (WebElement e : list) {
			System.out.println(e.getText());
		}
		list.get(6).click();
	}

}
